import numpy as np
import matplotlib.pyplot as plt

def verify():
    # 加载数据
    golden = np.fromfile("golden.bin", dtype=np.float32).reshape(512, 512)
    output = np.fromfile("output.bin", dtype=np.float32).reshape(512, 512)
    
    # 可视化对比
    plt.subplot(1,2,1), plt.imshow(golden, cmap='gray'), plt.title('Golden')
    plt.subplot(1,2,2), plt.imshow(output, cmap='gray'), plt.title('Output')
    
    # 计算误差（忽略边界）
    diff = np.abs(golden[2:-2, 2:-2] - output[2:-2, 2:-2])
    print(f"最大误差: {diff.max():.4f}")
    print(f"平均误差: {diff.mean():.4f}")
    print("验证结果: " + ("通过" if diff.max() < 2.0 else "失败"))
    plt.show()

if __name__ == "__main__":
    verify()